package cn.dtsmusic.chips.talk;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.chips.rong.methods.user.blacklist.Blacklist;
import com.chips.rong.methods.user.block.Block;
import com.chips.rong.model.Result;
import com.chips.rong.models.response.BlackListResult;
import com.chips.rong.models.response.ResponseResult;
import com.chips.rong.models.response.UserList;
import com.chips.rong.models.user.UserModel;

import cn.dtsmusic.model.domain.User;
import cn.dtsmusic.service.UserService;

public class ChipsUserTalk extends ChipsBaseTest {

	private static Log log = LogFactory.getLog(ChipsUserTalk.class );
	
	
	@Autowired
    private UserService userService;
	
	
	/**
	 * 用户 更新，并同步更新数据库
	 * @throws Exception
	 */
	 @Test
	 public void updateUser() throws Exception{
		 
		 com.chips.rong.methods.user.User user2 = rongCloud.user;
		 
		 UserModel user = new UserModel()
                 .setId("userxxd1")
                 .setName("chipsUser1-up")
                 .setPortrait("http://www.rongcloud.cn/images/logo.png");
		 
		 //通过 id  ， 更新用户的 name 和 Portrait 地址信息
		 Result update = user2.update(user);
		 
		 // 成功后更新数据库
		 if(update.getCode() == 200){
			 
			 User users = new User();
			 users.setUserId("userxxd1");
			 
			 User selectOne = userService.selectOne(users);
			 if(selectOne != null){
				 selectOne.setNickName("chipsUser1-up");
				 selectOne.setPortraitUri("http://www.rongcloud.cn/images/logo.png");
				 
				 userService.update(selectOne);
			 }
		 }
		 
		 // return,{"code":200} 
		 
		 log.debug("---update---"+user.toString()+", return,"+update);
		 
	 }
	 
	 /**
	  *  用户1 增加 用户2 和 3 为黑名单，然后在将用户2从黑名单移除 ， 调整接口返回参数转换的异常
	  * @throws Exception
	  */
	 @Test
	 public void blackList() throws Exception{
		 
		 //userxxd1  将   userxxd2  ， userxxd3  加入黑名单 ， 然后 解除 用户 userxxd2
		 com.chips.rong.methods.user.User user2 = rongCloud.user;
		 
		 Blacklist blackList = user2.blackList;
		 
		 
		 UserModel userBlack = new UserModel().setId("userxxd1");
		 UserModel[] blacklist2 = new UserModel[2] ;
		 UserModel  um2 = new UserModel();
		 um2.setId("userxxd2");
		 UserModel  um3 = new UserModel();
		 um3.setId("userxxd3");
		 blacklist2[0] = um2 ;
		 blacklist2[1] = um3 ;
		 userBlack.setBlacklist(blacklist2);
		 
		 // 给用户 1  ，增加2个黑名单
		 Result result = blackList.add(userBlack);
		 log.debug("用户的黑名单增加 2 和 3 ，状态:"+result.getCode());
		 
		 //获取用户1的黑名单
		 UserModel userBlack2 = new UserModel().setId("userxxd1");
		 UserList userList = blackList.getList(userBlack2);
		 log.debug("用户的黑名单为:"+userList.toString());
		 
		 
		 //取消用户1的一个黑名单
		 
		 UserModel userBlack1 = new UserModel().setId("userxxd1");
		 
		 UserModel[] blacklist3 = new UserModel[1] ;
		 UserModel  um4 = new UserModel();
		 um4.setId("userxxd2");
		 blacklist3[0] = um4 ;
		 
		 userBlack1.setBlacklist(blacklist3);
		 
		 Result remove = blackList.remove(userBlack1);
		 log.debug("用户的黑名单移除 2 状态:"+remove.toString());
		 
		 
		 //获取用户1的黑名单
		 UserModel userBlack3 = new UserModel().setId("userxxd1");
		 UserList userList2 = blackList.getList(userBlack3);
		 log.debug("用户的黑名单为:"+userList2.toString());
                
		 
		 
	 }
	 
	 @Test
	 public void blockUser() throws Exception{
		 
		 //将   userxxd4  30分钟   ， userxxd5  封了  60分钟 ， 然后 解除 用户 userxxd4
		 com.chips.rong.methods.user.User user2 = rongCloud.user;
		 
		 Block block = user2.block;
		 
		 
		 UserModel block4 = new UserModel().setId("userxxd4").setMinute(30);
		 UserModel block5 = new UserModel().setId("userxxd5").setMinute(60);
		 
		 
		 Result add = block.add(block4);
		 
		 log.debug("封用户4状态"+add.getCode());
		 Result add2 = block.add(block5);
		 log.debug("封用户5状态"+add2.getCode());
		 
		 
		 
		 
		 
		 Result list = block.getList();
		 
		 log.debug("封用户列表状态"+list.toString());
		 
		 
		 
		 ResponseResult remove = block.remove("userxxd4");
		 log.debug("解除用户4的封状态"+remove.getCode());
		 
		 
		 Result list1 = block.getList();
		 
		 log.debug("封用户列表状态"+list1.toString());
		 
		 
		 
		 
	 }
	 
	 
	 
	
}
